var q = 'http://gas-unit.googlecode.com/svn/trunk/gas-unit/gasUnit.js';
var s = UrlFetchApp.fetch(q).getContentText();

eval(s);


function add(number1, number2) {
  return number1 + number2;
}

function test_gasUnitAssertions() {
  
 var testFixture = new TestFixture('Tests on gasUnit assertions');
  
 testFixture.addTest(
    "Adding Two Positive Numbers",
    function () {
      this.assertAreEqual(3,add(1,2));
    });

 testFixture.addTest(
    "Adding A Positive And Negative Number",
    function () {
      this.assertAreEqual(-1,add(1,-2));
    });

 testFixture.addTest(
    "A Failing Test",
    function () {
      this.assertAreEqual(-2,add(1,-2));
    });

 testFixture.addTest(
    "Type Mismatch In Comparison",
    function () {
      this.assertAreNotEqual("Neil",add(1,-2));
    });

  testFixture.addTest(
    "Multiple Asserts",
    function () {
        this.assertAreEqual(true,false);
        this.assertAreEqual(true,true);
    });
    
  testFixture.addTest(
    "Handle Error Test",
    function () {
      this.blah.contains();
    });

  testFixture.addTest(
    "Handle False Test",
    function () {
      this.assertIsTrue(false, "Should Fail");
    });

  return testFixture.runTests().getResultsSummary();
 
}  
  
  
function test_FilteringByName() {
  
 var testFixture = new TestFixture('Tests By Name');
  
 testFixture.addTest(
    "Test1",
    function ()
    {
    });

 testFixture.addTest(
    "Test2",
    function ()
    {
    });

 testFixture.addTest(
    "Test3",
    function ()
    {
    });

  return testFixture.runTests(['Test1', 'Test2']).getResultsSummary();
    
}


function testGasUnitUsingGasUnit()
{

 var testFixture = new TestFixture('Test gasUnit results');

 testFixture.addTest(
    "Running tests should produce a list of tests with results",
    function ()
    {

      var resultsSummary = test_gasUnitAssertions();
      
      this.assertAreEqual(resultsSummary.total, 7, "Expected number of tests results mismatch"); 
      this.assertAreEqual(resultsSummary.passed, 3, "Expected number of tests passes mismatch"); 
      this.assertAreEqual(resultsSummary.failed, 3, "Expected number of tests fails mismatch"); 
      this.assertAreEqual(resultsSummary.errored, 1, "Expected number of tests errors mismatch"); 
      this.assertAreEqual(resultsSummary.ignored, 0, "Expected number of tests ignores mismatch");       

    });

 testFixture.addTest(
    "Running tests filtered by name should produce a reduced list of tests",
    function ()
    {
      var resultsSummary = test_FilteringByName();
      
      this.assertAreEqual(resultsSummary.total, 3, "Expected number of tests results mismatch"); 
      this.assertAreEqual(resultsSummary.passed, 2, "Expected number of tests passes mismatch"); 
      this.assertAreEqual(resultsSummary.failed, 0, "Expected number of tests fails mismatch"); 
      this.assertAreEqual(resultsSummary.errored, 0, "Expected number of tests errors mismatch"); 
      this.assertAreEqual(resultsSummary.ignored, 1, "Expected number of tests ignores mismatch");       
    });
          
  Logger.log(testFixture.createTextTestReport());       
  Logger.log(testFixture.runTests().createHtmlTestReport()); 

  //MailApp.sendEmail(emailAddress, title, Logger.getLog(), {htmlBody: testFixture.runTests().createHtmlTestReport() });
  //updateReportPage(testFixture.runTests().createHtmlTestReport(), '<site name>', '<report page name>');
  

  
}

function updateReportPage(htmlTestReport, siteName, reportName)
{
  var site = SitesApp.getSite(siteName);
  var reportPage = site.getChildByName(reportName);

  if ( reportPage != undefined )
  {
      reportPage.deletePage();
  }
  
  site.createWebPage(reportName, reportName, htmlTestReport);
}
